import { getUnitList } from '@/servers/api/base';
import { useIntl } from '@umijs/max';
import { Select } from 'antd';
import { useEffect, useState } from 'react';
type IFormDataType = {
    [key: string]: Array<ICheckItem>;
};
type ICheckItem = {
    label: string;
    value: string;
    checked?: boolean;
};
const FormSelect: React.FC<IBuildForm.Params> = (props) => {
    const { item } = props;
    const intl = useIntl();
    const type = item.details?.type || 'default';
    const [radioList, setRadioList] = useState<IFormDataType>({
        default: [
            // 默认 是否单选
            {
                label: intl.formatMessage({ id: '否' }),
                value: '1',
                checked: false,
            },
            {
                label: intl.formatMessage({ id: '是' }),
                value: '2',
                checked: false,
            },
        ],
        marginType: [
            // 金额单位
            {
                label: intl.formatMessage({ id: '元' }),
                value: '1',
                checked: true,
            },
            {
                label: intl.formatMessage({ id: '卢布' }),
                value: '2',
                checked: false,
            },
        ],
        priceUnit: [
            // 价格单位
            {
                label: intl.formatMessage({ id: '元' }),
                value: '元',
                checked: true,
            },
            {
                label: intl.formatMessage({ id: '卢布' }),
                value: '卢布',
                checked: false,
            },
        ],
        speedUnit: [
            // 速度单位
            {
                label: intl.formatMessage({ id: '天' }),
                value: '天',
            },
        ],
        location: [
            {
                value: '1',
                label: intl.formatMessage({ id: '中国货物' }),
            },
            {
                value: '2',
                label: intl.formatMessage({ id: '俄罗斯货物' }),
            },
            {
                value: '3',
                label: intl.formatMessage({ id: '在俄中国货物' }),
            },
            {
                value: '4',
                label: intl.formatMessage({ id: '在中俄罗斯货物' }),
            },
        ],
        numberUnit: [],
    });
    useEffect(() => {
        (async () => {
            const data = await getUnitList();
            const formatData = data.data.map((item: any) => {
                return {
                    label: item[intl.formatMessage({ id: 'item.name' })],
                    value: item[intl.formatMessage({ id: 'item.name' })],
                    checked: false,
                };
            });
            setRadioList({ ...radioList, numberUnit: formatData });
        })();
    }, []);

    return (
        <Select
            placeholder={props.placeholder}
            {...props}
            options={radioList[type]}
        />
    );
};
export default FormSelect;
